{#
This file is part of "vikuit".

Adapted on vikuit by Jose Blanco <jose.blanco[a]vikuit.com>

Copyright (c) Shaun Sephton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Shaun Sephton nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SHAUN SEPHTON BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#}
<html> 
    <head> 
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
        <title>CKEDitor | Select an image to embed</title> 
        <link rel="stylesheet" href="/static/js/editor/galleriffic/css/basic.css" type="text/css" /> 
        <link rel="stylesheet" href="/static/js/editor/galleriffic/css/galleriffic-2.css" type="text/css" /> 
        <script type="text/javascript" src="/static/js/editor/galleriffic/js/jquery-1.3.2.js"></script> 
        <script type="text/javascript" src="/static/js/editor/galleriffic/js/jquery.galleriffic.js"></script> 
        <script type="text/javascript" src="/static/js/editor/galleriffic/js/jquery.opacityrollover.js"></script> 
        <!-- We only want the thunbnails to display when javascript is disabled --> 
        <script type="text/javascript"> 
            document.write('<style>.noscript { display: none; }</style>');
            var auth = '{{ auth }}';
        </script> 
    </head> 
    <body> 
        <div id="page"> 
            <div id="container"> 
                <div id="gallery" class="content"> 
                    <div class="slideshow-container"> 
                        <div id="loading" class="loader"></div> 
                        <div id="slideshow" class="slideshow"></div> 
                    </div> 
                    <div id="caption" class="caption-container"></div> 
                </div> 
                <div id="thumbs" class="navigation"> 
                    <ul class="thumbs noscript"> 
                        {% for image in images %}
                        <li id="{{ image.url_path }}"> 
                            <a class="thumb" href="/images/gallery/thumbnail/{{ image.url_path }}"> 
                                <img src="/images/gallery/thumbnail/{{ image.url_path }}" width="48px" height="48px"/> 
                            </a> 
                            <div class="caption">
                                <div class="download" id="_{{ image.url_path }}"> 
                                    <input type="button" class="del" name="{{ image.url_path }}" value="{{ _('Delete from gallery') }}" /> | 
                                    <input type="button" class="embed" name="/images/gallery/thumbnail/{{ image.url_path }}" value="{{ _('Embed in article') }}" /> 
                                </div> 
                            </div> 
                        </li> 
                        {% endfor %}
                    </ul> 
                </div> 
                <div style="clear: both;"></div> 
            </div> 
        </div> 
        <script type="text/javascript"> 
            // helper functions
            function getUrlParam(paramName) {
                var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
                var match = window.location.search.match(reParam) ;
 
                return (match && match.length > 1) ? match[1] : '' ;
            }
                        
            $('.del').live('click', function() {
                var paramUrl = $(this).attr('name');

                var params = "act=del&auth="+auth+"&url="+paramUrl;
                var href = "/images/upload?"
                $.ajax({
                    type: 'get',
                    url: href,
                    data: params,
                    dataType: 'json',
                    async: true,
                    cache: false,
                    error: function(){
                            alert("Ooops!!");
                        },
                    success: function(json){
                            var saved = json.saved;
                            if (saved == true){
                                document.getElementById(paramUrl).innerHTML = "<img src=\"/static/images/cross.png\" width=\"48px\" height=\"48px\"/>";
                                document.getElementById("_"+paramUrl).innerHTML = " ";
                            } else {
                                alert(msg);
                            }
                        }
                });
                
            });
            
            function scale_image() {
                var max_width = 500;
                var image = $(".advance-link > img");
                var image_width = image.width();
                if (image_width > max_width) {
                    var aspect = image.height() / image_width;
                    var image_height = max_width * aspect;
                    image.width(max_width);
                    image.height(image_height);
                }
            }
 
            // embedder
            $('.embed').live('click', function() {
                var funcNum = getUrlParam('CKEditorFuncNum');
                var fileUrl = $(this).attr('name');
                window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
                window.close();
            });
 
            // galleriffic
            jQuery(document).ready(function($) {
                // We only want these styles applied when javascript is enabled
                $('div.navigation').css({'width' : '300px', 'float' : 'left'});
                $('div.content').css('display', 'block');
 
                // Initially set opacity on thumbs and add
                // additional styling for hover effect on thumbs
                var onMouseOutOpacity = 0.67;
                $('#thumbs ul.thumbs li').opacityrollover({
                    mouseOutOpacity:   onMouseOutOpacity,
                    mouseOverOpacity:  1.0,
                    fadeSpeed:         'fast',
                    exemptionSelector: '.selected'
                });
            
                // Initialize Advanced Galleriffic Gallery
                var gallery = $('#thumbs').galleriffic({
                    delay:                     2500,
                    numThumbs:                 15,
                    preloadAhead:              10,
                    enableTopPager:            true,
                    enableBottomPager:         true,
                    maxPagesToShow:            7,
                    imageContainerSel:         '#slideshow',
                    controlsContainerSel:      '#controls',
                    captionContainerSel:       '#caption',
                    loadingContainerSel:       '#loading',
                    renderSSControls:          true,
                    renderNavControls:         true,
                    playLinkText:              'Play Slideshow',
                    pauseLinkText:             'Pause Slideshow',
                    prevLinkText:              '&lsaquo; Previous Photo',
                    nextLinkText:              'Next Photo &rsaquo;',
                    nextPageLinkText:          'Next &rsaquo;',
                    prevPageLinkText:          '&lsaquo; Prev',
                    enableHistory:             false,
                    autoStart:                 false,
                    syncTransitions:           false,
                    defaultTransitionDuration: 500,
                    onSlideChange:             function(prevIndex, nextIndex) {
                        // 'this' refers to the gallery, which is an extension of $('#thumbs')
                        this.find('ul.thumbs').children()
                            .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                            .eq(nextIndex).fadeTo('fast', 1.0);
                    },
                    onPageTransitionOut:       function(callback) {
                        this.fadeTo('fast', 0.0, callback);
                    },
                    onPageTransitionIn:        function() {
                        this.fadeTo('fast', 1.0);
                    },
                    onTransitionIn:        function(newSlide, newCaption, isSync) {
                        scale_image();
                        newSlide.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
                        if (newCaption)
                            newCaption.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
                    }
                });
            });
        </script> 
    </body> 
</html> 